<%@page import="sdfi.lee.DAO.EmailDAO"%>
<%@page import="sdfi.lee.Entity.Email"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="<c:url value='/css/index.css'/>" />
<link rel="stylesheet" href="<c:url value='/css/level.css'/>" />
<script type="text/javascript" src="<c:url value='/js/jquery-1.6.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/index.js'/>"></script>
<script type="text/javascript">
$(function(){
	$("div a[index]").click(function(){
		$(this).css("color","#f00").parent("div").siblings("div").children("a").css("color","#000");
		var d="div[index="+$(this).attr("index")+']';
		
		$(d).siblings("div").hide();
		$(d).show();
				return false;
		});
	
	$("table tr:has(td):not(:last)").hover(function(){
			$(this).addClass("trover");
		},function(){
			$(this).removeClass("trover");
		});
	$("#all").click(function(){
	
		if($(this).is(":checked"))
		{
			$(this).next("span").text("取消").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",true);	
		}
		else
		{
		$(this).next("span").text("全选").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",false);		
		}
	});
	$("#allyidu").click(function(){
		
		if($(this).is(":checked"))
		{
			$(this).next("span").text("取消").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",true);	
		}
		else
		{
		$(this).next("span").text("全选").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",false);		
		}
	});
	$("#allyihui").click(function(){
		
		if($(this).is(":checked"))
		{
			$(this).next("span").text("取消").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",true);	
		}
		else
		{
		$(this).next("span").text("全选").parents("tr").siblings("tr:not(th)").children("td:has(:checkbox)").children(":checkbox").attr("checked",false);		
		}
	});
	/*标记为已读*/
	$("#yidu").click(function(){
		if($(".div_myinfo[index=0] table :checkbox:not(:last):checked").size()<=0)
		{
			alert("请选择邮件");
		}
		else
		{
			
			var list="";
			$.each($(".div_myinfo[index=0] table :checkbox:not(:last):checked"),function(index,check){
				list+="id="+$(check).val()+"&";	
			});
			list=list.substring(0,list.length-1);
			var option={
				url:'../SetMailReaded?'+list,
				type:"get",
				dataType:"text",
				success:function(data,status)
				{
					if(data=="success")
						{
							window.location.reload();
						}
					else
						{
						alert("对不起失败");
						}
				},
				error:function(xhr,status)
				{
						alert("服务器忙");
				}
			};
			$.ajax(option);
		}
	});
	function deletemail(index,bt)
	{
		var sl=".div_myinfo[index="+index+"] table :checkbox:not(:last):checked";
		if($(sl).size()<=0)
		{	
		alert("请选择要删除的邮件");
		return false;
		}
		var list="";
		$.each($(sl),function(index,check){
			list+="id="+$(check).val()+"&";	
		});
		list=list.substring(0,list.length-1);
		var option={
			url:'../DeleteEmail?'+list,
			type:"get",
			dataType:"text",
			success:function(data,status)
			{
				
				if(data=="success")
					{
						$.each($(sl),function(index,check){
						$(check).parents("tr").remove();
							});
					}
				else
					{
						alert("对不起失败");
					}
			},
			error:function(xhr,status)
			{
					alert("服务器忙");
			}
		};
		$.ajax(option);
	}
	$("#laidl").click(function(){
		deletemail(0,$(this));
		});
	$("#yidudl").click(function(){
		deletemail(1,$(this));
		});
	$("#yihuidl").click(function(){
		deletemail(2,$(this));
		});
		
	$("tr[value] td:has(a) a").click(function(event){
		
		
			window.showModalDialog("showemail.jsp?isread="+$(this).attr("value")+"&id="+$(this).parents("tr").attr("value"),"邮件详情","dialogTop:200px;dialogLeft:300px;dialogHeight:400px; dialogWidth:400px;");
	
		});
});
</script>
<style type="text/css">
<!--
	.trover{
		background-color:#FFE0D0;	}
	table{
		border:1px solid #CCC; 
		margin-top:5px;
		width:98%;
		border-bottom:none;
		}
		tr{
			cursor:pointer;
			
		}
		th{
			text-align:center;
			border:1px solid #ccc;
			background-color:#CCC;
				padding:5px;
		}
		td span{
			font:Verdana, Geneva, sans-serif;
			font-size:12px;		}
		td{
			font:Verdana, Geneva, sans-serif;
			font-size:14px;
			text-align:left;
			border-bottom:1px solid #ccc;
		
			padding:5px;
		}
-->
</style>
<title>主任信箱</title>
</head>
<body>
<%
	EmailDAO maildao=new EmailDAO();
	List<Email> newlist=maildao.getEmailByType(1,20,0);
	List<Email> newyidu=maildao.getEmailByType(1,20,1);
	List<Email> newyihui=maildao.getEmailByType(1,20,2);
	request.setAttribute("newlist",newlist);
	request.setAttribute("newyidu",newyidu);
	request.setAttribute("newyihui",newyihui);
%>
<div class="logo"></div>
    <div class="navg" style="text-align:center">
    	<ul>
        	<li ><a href="<c:url value='/index.jsp' />" >首页</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/center/center.jsp' />" >创制中心</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/news/n_list.jsp' />" >最新动态</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/achievement/a_list.jsp' />" >最新成果</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/news/newslist.jsp?type=2&pg=1' />" >政策法规</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/news/o_newslist.jsp?type=4&pg=1' />" >发展规划</a></li>
            <li>|</li>
            <li ><a href="<c:url value='/news/o_newslist.jsp?type=5&pg=1' />" >服务指南</a></li>
           <li>|</li>
            <li ><a href="" >网站地图</a></li>
             <li>|</li>
            <li ><a href="<c:url value='/zhuren/zhurenxinxiang.jsp'/>" class="<c:choose>
             	<c:when test='${sessionScope.count<=0}'>no_mail</c:when>
             	<c:otherwise>new_mail</c:otherwise>
             </c:choose>" style="padding-right:15px;">主任信箱</a></li>
            
        </ul>
    </div>
    <div class="weltop">
    	<span id="showtime"></span>
        <div id="searchquestion">
        	<form id="fform" action="<c:url value='/question/question.action' />"><input type="text" id="question"  />&nbsp;<input type="submit" value="提问" id="qa" onclick="return false" /></form>
        </div>
    </div>

<div class="divhead">当前位置:<a href="<c:url value='/index.jsp'/>">首页</a>
&gt;&nbsp;主任信箱
</div>
<div id="divshowcontain">
	<div class="div_right_contain" >
		<div class="div_myinfo" index="0">
			<table cellspacing="0" >
				<tr>
					<th >
						主题
					</th>
					<th >
						发信人
					</th>
					<th >
						邮件地址
					</th>
					<th >
						时间
					</th>
				</tr>
				<c:choose>
					<c:when test="${fn:length(requestScope.newlist)>0}">
					<c:forEach items="${requestScope.newlist}" var="email">
					<tr value="${email.id}">
						<td>
                        	<input value="${email.id}" type="checkbox">
						<a href="#" value="true">${fn:substring(email.content,0,20)}</a>
						</td>
						<td>
							${email.replayName}
						</td>
						<td>
							${email.relayTo}
						</td>
						<td>
							${email.senddate }
						</td>
					</tr>
				</c:forEach>
				<tr>
					<td colspan="4">
                    	<input type="checkbox" id="all"><span>全选</span>
                        <input type="button" value="删除" id="laidl">
                        <input type="button" value="标记为已读" id="yidu">
                    </td>
				</tr>
					</c:when>
					<c:otherwise>
						<tr>
							<td colspan="4">暂时无消息</td>
						</tr>
						
					</c:otherwise>
				</c:choose>
				
			</table>
		</div>
		<div class="div_myinfo" index="1" style="display:none">
			<table cellspacing="0" >
				<tr>
					<th >
						主题
					</th>
					<th >
						发信人
					</th>
					<th >
						邮件
					</th>
					<th >
						时间
					</th>
				</tr>
				<c:choose>
					<c:when test="${fn:length(requestScope.newyidu)>0}">
				<c:forEach items="${requestScope.newyidu}" var="email">
					<tr value="${email.id}">
						<td>
                        	<input value="${email.id}" type="checkbox">
							<a href="#" value="false">${fn:substring(email.content,0,20)}</a>
						</td>
						<td>
							${email.replayName}
						</td>
						<td>
							${email.relayTo}
						</td>
						<td>
							${email.senddate }
						</td>
					</tr>
				</c:forEach>
				<tr>
					<td colspan="4">
                    	<input type="checkbox" id="allyidu"><span>全选</span>
                        <input type="button" value="删除" id="yidudl">
                       
                    </td>
				</tr>
				</c:when>
						<c:otherwise>
						<tr>
							<td colspan="4">暂时无消息</td>
						</tr>
						
					</c:otherwise>
				</c:choose>
			</table>
		</div>
		<div class="div_myinfo" index="2" style="display:none">
		<table cellspacing="0" >
				<tr>
					<th >
						主题
					</th>
					<th >
						发信人
					</th>
					<th >
						邮件
					</th>
					<th >
						时间
					</th>
				</tr>
				<c:choose>
					<c:when test="${fn:length(requestScope.newyihui)>0}">
				<c:forEach items="${requestScope.newyihui}" var="email">
					<tr value="${email.id}">
						<td>
                        	<input value="${email.id}" type="checkbox">
							<a value="false">${fn:substring(email.content,0,20)}</a>
						</td>
						<td>
							${email.replayName}
						</td>
						<td>
							${email.relayTo}
						</td>
						<td>
							${email.senddate }
						</td>
					</tr>
				</c:forEach>
				
				<tr>
					<td colspan="4">
                    	<input type="checkbox" id="allyihui"><span>全选</span>
                       <input type="button" value="删除" id="yihuidl">
                   
                    </td>
				</tr>
				</c:when>
						<c:otherwise>
						<tr>
							<td colspan="4">暂时无消息</td>
						</tr>
						
					</c:otherwise>
				</c:choose>
			</table>
		</div>


	</div>
	<div class="div_left_contain">
    
		 <div class="div_left_nav" >	<a  style="color:#f00" href="#" index="0">读者来信</a></div>
		 <div class="div_left_nav" > 	<a  index="1" href="#">已读来信</a></div>
		 <div class="div_left_nav" > 	<a  index="2" href="#">已回来信</a></div>
      <div style="clear:right;margin:0px;"></div>
	</div>
	    
	</div>
</body>
</html>